package InitialRank;

import hashLinkGraph.ID;

import java.io.IOException;

import mapred.AbstractMapper;
import mapred.util.Bytes;

import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;


public class HashHostRank_Mapper extends AbstractMapper<Text, Text, BytesWritable, BytesWritable>{

	@Override
	public void map(Text key, Text value,
			OutputCollector<BytesWritable, BytesWritable> output,
			Reporter reporter) throws IOException {
		// TODO Auto-generated method stub
		try {
			ID k = new ID(key.toString().trim());
			String v = value.toString().trim();
			String[] hostrank = v.split("\t");
			byte[] fuxin = Bytes.Double2Bytes(Double.parseDouble(hostrank[1]));
			output.collect(new BytesWritable(k.toHost()), new BytesWritable(fuxin));
		} catch(Exception e) {
			reporter.incrCounter("HostRank", "invalid", 1);
		}
		
		
	}

}
